function [scheduledTargets, status] = HR_SelectBestTargetString(PQ, targetStrings)
%HR_SelectBestTargetString Summary of this function goes here
%   Detailed explanation goes here

attemptedTargets(1:PQ_Size(PQ)) = NaN;
scheduledTargets = [];
status = 0;

if (size(targetStrings, 2) <= 0)
  return;
elseif (size(targetStrings, 2) > 1)
  for p = 1:PQ_Priorities(PQ)
    for t = 1:PQ_Size(PQ)
      % randomly select each task in the priority queue
      while 1
        attemptedTargets(t) = ceil(rand()*PQ_Size(PQ));
        been_done = 0;
        for s = 1:t-1
          if attemptedTargets(s) == attemptedTargets(t)
            been_done = 1;
            break;
          end
        end
        if ~been_done
          break;
        end
      end

      [Task, status] = PQ_Fetch_Task(PQ, attemptedTargets(t), PQ_Priorities(PQ)+1-p);
      if ~status
        continue;
      end

      validTargetStrings = true(size(targetStrings));      % Make a backup of validTargetStrings, in case we end up clearing it out
      for stringCntr = 1:size(targetStrings, 2)
          
          if ~validTargetStrings(stringCntr)
              continue;
          end
          
          found = 0;
          for posCntr = 1:size(targetStrings(stringCntr).string, 2)
              if (targetStrings(stringCntr).string(posCntr) == Task.id)
                  found = 1;
                  break;
              end
          end
          
          if ~found
              % remove string from selection
              validTargetStrings(stringCntr) = 0;
              %          targetStrings = [targetStrings(1:stringCntr-1) targetStrings(stringCntr+1:size(targetStrings, 2))];
              %         else
              %           stringCntr = stringCntr + 1;
          end
      end
      
      if (any(validTargetStrings))
          % Some valid targetStrings, remain, thus apply change
          targetStrings = targetStrings(validTargetStrings);
      end
      
      if (length(targetStrings) == 1)
        break;
      end
    end
    if (length(targetStrings) == 1)
      break;
    end
  end
end

scheduledTargets = targetStrings.string;
status = 1;
end